package ooday03.homework.myclass;
import ooday03.homework.impl.Swim;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[] animals = new Animal[4];

        animals[0] = new Dog("小狗",2,"黑");
        animals[1] = new Chick("小鸡",1,"黄");
        animals[2] = new Flsh("小鱼",3,"灰");
        animals[3] = new Dog("小狗",4,"黑");


        for (Animal a : animals){
            System.out.println(a);
        }

        System.out.println("----------------------------");

        for (int i=0;i<animals.length;i++){
            animals[i].eat();
            animals[i].drink();

            if(animals[i] instanceof Dog){
                Dog dog = (Dog)animals[i];
                dog.lookHome();
            }


            if(animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }

            if(animals[i] instanceof Swim){
                Swim swim = (Swim) animals[i];
                swim.swim();
            }
        }
        int[] a= new int[4];
        System.out.println(a[4]);

    }
}
